Skip to content

Conversation

@mattpollock
Copy link
Contributor

@mattpollock mattpollock commented Jan 14, 2026

@Ramanth, @saigiridhar21, @wing328

This PR handles 2 related issues pertaining to deserializing responses in generated R clients.

  1. Previously the deserializeObj() method of the API client only supported array[...] types, not set[...] types. That is fixed here by collapsing both to a temporary collection[...] type which is only used for a regex to identify collections and pull out the inner type.
  2. The jsonlite library will sometimes parse nested JSON arrays as an R data.frame nested within an R list. I've provided an example as a comment near the change. This PR handles this case so that nested objects are correctly parsed into the target R6 objects. Current behavior is that they are returned, unexpectedly, as data frames.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Fixes deserialization in generated R clients. Adds support for set[...] and correctly parses nested arrays from jsonlite so APIs return proper R6 objects instead of data.frames.

  • Bug Fixes
    • Treat set[...] the same as array[...] by normalizing to collection[...] when extracting inner types.
    • Unwrap list-wrapped data.frames before deserializing nested objects to R6 classes.

Written for commit 511f575. Summary will update on new commits.

Comment on lines +379 to +381
if (is.list(obj) && length(obj) == 1 && is.data.frame(obj[[1]])) {
obj <- obj[[1]]
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This situation arises when parsing responses that have fields that are arrays of other response models. E.g. consider a Person response with a nested family field populated with an array of Relationship objects

txt <- '[{"name": "bob", "family":[{"name":"joe", "relationship":"dad"},{"name":"sue", "relationship":"mom"}]}]'
json <- jsonlite::fromJSON(txt)
class(json$family)
#> [1] "list"
class(json$family[[1]])
#> [1] "data.frame"

Here the family field is initially parsed as a list of length 1, populated with a data.frame. This is not handled in the current code because nrow(json$family) is NULL. This is why we get some unexpected data.frame return values where we should get a list of R6 objects.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="modules/openapi-generator/src/main/resources/r/api_client.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/r/api_client.mustache:379">
P2: Nested collections with single outer element are flattened: unwrapping list-of-data.frame drops one collection dimension</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 6 files (changes from recent commits).

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="samples/client/petstore/R-httr2-wrapper/R/api_client.R">

<violation number="1" location="samples/client/petstore/R-httr2-wrapper/R/api_client.R:380">
P2: Non-primitive collections that jsonlite parses as lists (no `nrow`) return NULL instead of deserializing elements, dropping set/array of objects.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/r/libraries/httr2/api_client.mustache:391">
P2: Nested collections are flattened: unwrapping `list(data.frame)` collapses the outer collection when deserializing `collection[collection[T]]`, returning the wrong shape for length-1 outer arrays.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@wing328
Copy link
Member

wing328 commented Jan 18, 2026

r integration tests passed via #22721

@wing328 wing328 merged commit 428d483 into OpenAPITools:master Jan 18, 2026
16 checks passed
@wing328 wing328 added this to the 7.19.0 milestone Jan 19, 2026
@mattpollock
Copy link
Contributor Author

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants